package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(20);not null; commit:'商品标题'"`
	Price  float64 `gorm:"type:decimal(10,2);not null; commit:'商品价格'"`
	Cover  string  `gorm:"type:varchar(255);not null; commit:'商品封面'"`
	Stock  int64   `gorm:"type:int(10);not null; commit:'商品库存'"`
	Status string  `gorm:"type:enum('已审核','未审核');not null; commit:'商品状态'"`
	Likes  int64   `gorm:"type:int(10);not null; commit:'商品点赞数'"`
	Type   string  `gorm:"type:enum('数码','水果');not null; commit:'商品类型'"`
}

func (g *Goods) List(Status string) (good []*Goods) {
	if Status == "" {
		DB.Debug().Find(&good)
	} else {
		DB.Debug().Where("status=?", Status).Find(&good)
	}
	return
}

func (g *Goods) Create() error {
	return DB.Create(&g).Error
}

func (g *Goods) List10() (good []*Goods) {
	DB.Debug().Order("likes desc").Limit(10).Find(&good)
	return
}
func (g *Goods) GoodsInfo(id int) (good []*Goods) {
	DB.Debug().Where("id=?", id).Find(&good)
	return
}
func (g *Goods) GoodsStarts(Id int, Status string) (good []*Goods) {
	DB.Model(&Goods{}).Where("id", Id).Update("status", Status).Find(&good)
	return
}
